<?php
// 添加新权限


$rolename=$_REQUEST["rolename"];//权限名称
$rolefile=$_FILES["rolefile"]; //权限上传路径

// 以二进制只读模式打开文件
$file=fopen($rolefile["tmp_name"],"rb");
// 获取文件大小
$length=filesize($rolefile["tmp_name"]);
$content=fread($file,$length);
$content=addslashes($content);
fclose($file);
function getConn() {
    $url = "localhost:3306";
    $user = "root";
    $password = "";// 如果没有密码, 就是空字符串
    $database = "videoDatas";
    $conn = mysqli_connect($url, $user, $password, $database);
    mysqli_query($conn, "set names utf8");
    return $conn;
}

$conn = getConn();
$sql="insert into t_power (powerName, powerPath) values ('{$rolename}','11')";
$result = mysqli_query($conn, $sql);
// echo $rolename
// require_once("./DButil.php");
// 文件上传保存路径
// $Path="d:/Users/User/Desktop/dxy/videoCourse_stu/videoCourse_stu/img/";
// $oldName = $rolefile["name"];
// // $newName=time().mt_rand(1000,9999).$_FILES["rolefile"]["tmp_name"];
// $newName = time() . mt_rand(1000, 9999) . substr($oldName, mb_strpos($oldName, "."));

// if(move_uploaded_file($_FILES["rolefile"]["tmp_name"], $Path . $newName) && $rolename!='' ){

//     $arr=update($sql);
// query($sql);
// // }
//  header("Content-Type:application/json;charset=utf-8");
//  echo json_encode($arr);
if($result){
    echo "<div>商品添加成功</div>";
} else {
    $msg = mysqli_error($conn);
     echo "<div>商品添加失败:{$msg}</div>";
    }
?>